package com.example.service;

import org.apache.curator.RetryLoop;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.transaction.CuratorTransaction;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
import org.apache.curator.framework.recipes.barriers.DistributedBarrier;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.apache.curator.framework.recipes.leader.LeaderLatch;
import org.apache.curator.framework.recipes.leader.LeaderSelector;
import org.apache.curator.framework.recipes.leader.LeaderSelectorListener;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock;
import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex;
import org.apache.curator.framework.recipes.queue.*;
import org.apache.curator.framework.recipes.shared.SharedCount;
import org.apache.curator.retry.RetryNTimes;
import org.apache.zookeeper.CreateMode;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

public interface ZookeeperService {

    public static final String PREF = "/";

    public CuratorFramework getCuratorFramework();

    public RetryLoop getRetryLoop();

    public boolean isExistNode(final String path) throws Exception;

    public void createNode(CreateMode mode, String path) throws Exception;

    public void setNodeData(String path, String nodeData) throws Exception;

    public String createNodeAndData(CreateMode mode, String path, String nodeData) throws Exception;

    public String getNodeData(String path) throws Exception;

    public List<String> getNodeChild(String path) throws Exception;

    public Map<String, String> getNodeChildMap(String path) throws Exception;

    public void deleteNode(String path, Boolean recursive) throws Exception;

    public void watchNode(String path, NodeCacheListener nodeCacheListener) throws Exception;

    public void watchPath(String path, PathChildrenCacheListener pathChildrenCacheListener) throws Exception;

    public LeaderLatch getLeaderLatch(String path) throws Exception;

    public DistributedAtomicLong getDistributedAtomicLong(String path, RetryNTimes retryNTimes);

    public SharedCount getSharedCount(String path, int val);

    public CuratorTransaction getCuratorTransaction(String path);

    public InterProcessMutex getInterProcessMutex(String path);

    public InterProcessReadWriteLock getInterProcessReadWriteLock(String path);

    public InterProcessSemaphoreMutex getInterProcessSemaphoreMutex(String path);

    public DistributedBarrier getDistributedBarrier(String path);

    public LeaderSelector getLeaderSelector(String leaderPath, ExecutorService executorService, LeaderSelectorListener listener);

    public SimpleDistributedQueue getSimpleDistributedQueue(String path);

    public DistributedPriorityQueue getDistributedPriorityQueue(QueueConsumer queueConsumer, QueueSerializer queueSerializer, String path, int minItemsBeforeRefresh);

    public DistributedQueue getDistributedQueue(QueueConsumer queueConsumer, QueueSerializer queueSerializer, String path);

    public DistributedDelayQueue getDistributedDelayQueue(QueueConsumer queueConsumer, QueueSerializer queueSerializer, String path);
}
